const tools = {
	replaceInfoImg: (info) => {
		if (!info) {
			return info;
		}
		// 正则表达式匹配<img开始的所有标签，但不包括>  
		const regex = /<img([^>]*)>/g;
		let style = 'display: block;max-width: 90vw;height: auto;margin: 10px auto;'

		let replacedString = info.replace(regex, function(match, p1) {
			// p1是匹配到的第一个分组，即<img标签的所有属性  
			// 在属性前插入style属性  
			return `<img style="${style}"${p1 ? ' ' + p1 : ''}>`;
		});
		replacedString = replacedString.replace(/\r\n/g, "<br>")
		replacedString = replacedString.replace(/\n/g, "<br>")
		replacedString = replacedString.replace(/\r/g, "<br>")
		return replacedString
	},
	concatJson: (...jsons) => {
		let json = {}
		for (let index = 0; index < jsons.length; index++) {
			let element = jsons[index]
			for (let key in element) {
				json[key] = element[key]
			}
		}
		return json
	},
	formatDate: (value, format = 'yyyy-MM-dd hh:mm:ss') => {
		try {
			let time = new Date()
			if (typeof value === 'number') {
				time.setTime(parseInt(value.toString()))
			} else if (value instanceof Date) {
				time = value
			}
			let year = time.getFullYear() + ''
			let month = time.getMonth() + 1 + ''
			let day = time.getDate() + ''
			let hour = time.getHours() + ''
			let minute = time.getMinutes() + ''
			let second = time.getSeconds() + ''
			let ms = time.getMilliseconds() + ''
			month = month.padStart(2, '0')
			day = day.padStart(2, '0')
			hour = hour.padStart(2, '0')
			minute = minute.padStart(2, '0')
			second = second.padStart(2, '0')
			ms = ms.padStart(3, '0')

			format = format.replace(/yyyy/g, year)
			format = format.replace(/MM/g, month)
			format = format.replace(/dd/g, day)
			format = format.replace(/hh/g, hour)
			format = format.replace(/mm/g, minute)
			format = format.replace(/ss/g, second)
			format = format.replace(/ms/g, ms)
			return format
		} catch (ex) {
			log.error(ex)
			return ''
		}
	}
}

export default tools

export {
	tools
}